package com.test.nnooolwdeaer.util_wooden;

import android.os.Handler;
import android.os.Looper;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadUtil_wooden {

    private final ExecutorService cachedThreadPool_wooden;
    private final Handler handler_wooden;

    private static class Inner_wooden {
        private static final ThreadUtil_wooden instance_wooden = new ThreadUtil_wooden();
    }

    private ThreadUtil_wooden(){
        cachedThreadPool_wooden = Executors.newCachedThreadPool();
        handler_wooden = new Handler(Looper.getMainLooper());
    }

    public static ThreadUtil_wooden getInstance_wooden(){
        return Inner_wooden.instance_wooden;
    }

    public void runOnChildThread_wooden(Runnable runnable){
        cachedThreadPool_wooden.execute(runnable);
    }

    public void runOnUiThread_wooden(Runnable runnable){
        handler_wooden.post(runnable);
    }

    public void postDelay_wooden(Runnable runnable, long delayMillis){
        handler_wooden.postDelayed(() -> {
            if (Looper.myLooper()!=Looper.getMainLooper()) runOnChildThread_wooden(runnable);
            else runnable.run();
        },delayMillis);
    }

}
